package com.qumitech.visualnovel.controller.rest;

import com.qumitech.visualnovel.console.excel.ExportExcel;
import com.qumitech.visualnovel.console.excel.StateField;
import com.qumitech.visualnovel.console.excel.State;
import com.qumitech.visualnovel.console.excel.UnitField;
import com.qumitech.visualnovel.model.common.BaseRsp;
import com.qumitech.visualnovel.model.common.ResultEnum;
import com.qumitech.visualnovel.controller.vo.withdraw.WithdrawAdminQueryDTO;
import com.qumitech.visualnovel.controller.vo.withdraw.WithdrawExcelVo;
import com.qumitech.visualnovel.controller.vo.withdraw.WithdrawVo;
import com.qumitech.visualnovel.service.wallet.WalletService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;


/**
 * @Author :  ZhChNing
 * @Descriptiom :
 * @Date Created in 2019/1/28 17:36
 */

@RestController
@RequestMapping("/api/wallet")
public class WalletController {
    @Autowired
    private WalletService walletService;

    @RequestMapping(value = "/withdraw", method = RequestMethod.GET)
    @ExportExcel(itemCls = WithdrawExcelVo.class,
            listKey = "item",
            unitFields = {
                    @UnitField(key="amount", unit = 10000),
                    @UnitField(key="realAmount", unit = 10000),
                    @UnitField(key="taxAmount", unit = 10000)
            },
            stateFields = {
                @StateField(key="state", states = {
                    @State(state="0", display = "待处理"),
                    @State(state="1", display = "审核不通过"),
                    @State(state="2", display = "审核通过"),
                    @State(state="3", display = "转账成功"),
                    @State(state="4", display = "转账失败"),
                })
            })
    public BaseRsp listWithdarw(WithdrawAdminQueryDTO queryDTO) {

        return new BaseRsp(ResultEnum.SUCCESS, walletService.listWallet(queryDTO));
    }

    @RequestMapping(value = "/withdraw/audit", method = RequestMethod.POST)
    public BaseRsp auditWithdarw( @RequestBody WithdrawVo withdrawVo) {
        walletService.updateWithdrawState(withdrawVo);
        return new BaseRsp(ResultEnum.SUCCESS);
    }


    @RequestMapping(value = "/withdraw/import", method = RequestMethod.POST)
    public BaseRsp listWithdarwImport(@RequestBody WithdrawAdminQueryDTO queryDTO, HttpServletResponse request) {
        walletService.exportMultipartFile(queryDTO, request);
        return new BaseRsp(ResultEnum.SUCCESS);
    }

    @RequestMapping(value = "/withdraw/collect", method = RequestMethod.GET)
    public BaseRsp withdrawCollect(WithdrawAdminQueryDTO queryDTO) {
        return new BaseRsp(ResultEnum.SUCCESS, walletService.withdrawCollect(queryDTO));
    }


    @RequestMapping(value = "/withdraw/collect/import", method = RequestMethod.POST)
    public BaseRsp collectWithdarwImport(@RequestBody WithdrawAdminQueryDTO queryDTO, HttpServletResponse request) {
        walletService.exportMultipartCollectFile(queryDTO, request);
        return new BaseRsp(ResultEnum.SUCCESS);
    }



    @RequestMapping(value = "/withdraw/{withdraw_id}/retry/deal_withdraw", method = RequestMethod.POST)
    public BaseRsp retryDealWithdraw(@PathVariable("withdraw_id") String withdrawId) {
        walletService.retryDealWithdraw(withdrawId);
        return new BaseRsp(ResultEnum.SUCCESS);
    }
}
